
#include "SingleDuplicateA.h"
#include "Common/EventDefine.h"
#include "Duplicate/DuplicateMgr.h"
#include "Character/Part.h"
#include "Character/monster/MonsterMgr.h"
#include "Character/monster/MonsterRefCfg.h"


SingleDuplicateA::SingleDuplicateA()
{
	m_byType = (int8_t)EDuplicateType::EDuplicateType_SingleA;
}

SingleDuplicateA::~SingleDuplicateA()
{

}

bool SingleDuplicateA::Init(uint32_t nDuplicateID, uint32_t nSceneID, IBrushMonster *pBrush)
{
	return Duplicate::Init(nDuplicateID, nSceneID, pBrush);
}

//
void SingleDuplicateA::UnInit()
{
	Duplicate::UnInit();
}

void SingleDuplicateA::OnTimerUpdate(uint32_t nTimerID)
{
	switch (nTimerID)
	{
	case ETimer_Flop:
	{
		//翻牌结束
		OnCommon_FlopStateEnd();
	}
	break;
	case ETimer_Clean:
	{
		OnCommon_CleanStateEnd();
	}
	break;
	case ETimer_Destory:
	{
		LogDebugFmtPrint("[logic] SingleDuplicateA destory .... duplicateid:%u , sceneid:%u, mapid:%u ", m_nDuplicateID, m_nSceneID, m_nMapID);
		//回收
		OnCommon_DestoryStateEnd();
	}
	break;
	}
}

void SingleDuplicateA::OnExecuteEvent(uint16_t nEventID, uint32_t nSrcID, uint8_t bySrcType, void *pContext, int32_t nLen)
{
	switch (nEventID)
	{
	case EVENT_CREATURE_DEAD:
	{
	}
	break;
	case EVENT_ENTER_SCENE:
	{
	}
	break;
	case EVENT_DISCONNECT:
	{
	}
	break;
	}
}

//生物进入场景
void SingleDuplicateA::OnCreatureEnter(Creature *pCreature)
{
	/*if (nullptr == pCreature)
	{
	return;
	}
	if (CREATURE_PLAYER == pCreature->CreatureKind())
	{
	//订阅角色刷怪事件
	if (!g_GetEvent()->Subscribe(this, EVENT_CREATURE_DEAD, pCreature->GetCid(), CREATURE_MONSTER, "NewDuplicate"))
	{
	LogErrFmtPrint("[logic] NewDuplicate::EnterDuplicate....Subscribe monster dead event failed....");
	}

	//订阅角色掉线事件
	if (!g_GetEvent()->Subscribe(this, EVENT_DISCONNECT, pCreature->GetCid(), CREATURE_PLAYER, "NewDuplicate"))
	{
	LogErrFmtPrint("[logic] NewDuplicate::EnterDuplicate....Subscribe player disconnect event  failed....");
	}

	//订阅角色死亡事件
	if (!g_GetEvent()->Subscribe(this, EVENT_CREATURE_DEAD, pCreature->GetCid(), CREATURE_PLAYER, "NewDuplicate"))
	{
	LogErrFmtPrint("[logic] NewDuplicate::EnterDuplicate....Subscribe player dead event  failed....");
	}

	LogDebugFmtPrint("[logic] NewDuplicate::EnterDuplicate success...cid:%u ,duplicateid:%u", pCreature->GetCid(), m_nDuplicateID);
	}*/
}

//生物离开副本
void SingleDuplicateA::OnPlayerLeave(Player *pPlayer)
{
}

//是否能进入
bool SingleDuplicateA::OnCanEnter(Creature *pCreature)
{
	//新手副本准备状态才能进入
	if (GetDuplicateState() == (int8_t)EDuplicateState::EDuplicateState_Ready)
	{
		if (m_setPlayer.size() < 1) //活动副本只允许一个人
		{
			return true;
		}
	}

	return false;
}

//进入区域
bool SingleDuplicateA::OnEnterArea(uint32_t nAreaID)
{
	nAreaID = nAreaID;
	return true;
}

//复活
void SingleDuplicateA::OnRelive(Player *pPlayer, int8_t byType)
{
	pPlayer = pPlayer;
	byType = byType;
}

void SingleDuplicateA::OnReady_State()
{

}

void SingleDuplicateA::OnBegin_State()
{
	OnCommon_DupBeginState();
}

void SingleDuplicateA::OnFinish_State()
{
	OnCommon_DupFinishState();
}

void SingleDuplicateA::OnFlop_State()
{
	//设置抽奖时间 20s
	LogDebugFmtPrint("[logic] SingleDuplicateA::OnDuplicateState_Flop....duplicateid:%u , sceneid:%u ", m_nDuplicateID, m_nSceneID);
	OnCommon_DupFlopState();
}

void SingleDuplicateA::OnClean_State()
{
	OnCommon_DupFlopState();
}

void SingleDuplicateA::OnDestory_State()
{
	OnCommon_DupDestoryState();
}
